<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-11-28 14:12
 *
 * Version: 2.0
 */

namespace App\Modules\RedBag\Controllers;


use App\Lib\Facades\FLAuth;
use App\Modules\RedBag\Services\RedBagService;
use App\Modules\RedBag\Validators\RedBagBarberControllerValidator;
use Flower\Core\Http\BaseController;
use Illuminate\Http\Request;

class RedBagBarberController extends BaseController
{

	protected $redBagService;
	public function __construct(RedBagService $redBagService)
	{
		$this->redBagService = $redBagService;
	}


	public function getRules()
	{
		return RedBagBarberControllerValidator::getRules(); // TODO: Change the autogenerated stub
	}

	/**
	 * 发红包
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\NotFoundException
	 */
	public function send(Request $request){
		$params = $request->all();
		$result = $this->redBagService->sendRedBagToMember($params,FLAuth::id());
		return $this->handleApiResult($result);
	}

	/**
	 * 回收红包
	 * @throws \App\Exceptions\NotFoundException
	 */
	public function redBagBack(Request $request){
		$userId = FLAuth::id();
		$storeId = $request->input('store_id');
		$result = $this->redBagService->backRedBag($userId,$storeId);
		return $this->handleApiResult($result);
	}
}